package org.example.apifallback.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zengxiaoyu
 * @date 2025/7/31 19:05
 */
public class FullNameUtils {

    private  static final Pattern pattern = Pattern.compile("([a-zA-Z0-9_]+\\.)+([a-zA-Z0-9_]+)");

    public static List<String> fullNames(String type) {
        List<String> fullNames = new ArrayList<>();
        Matcher matcher = pattern.matcher(type);
        while (matcher.find()) {
            String fullName = matcher.group(0);
            String shortName = matcher.group(2); // 提取类名
            fullNames.add(fullName);
        }
        return fullNames;
    }


    public static String deepReplace(String type) {

        Matcher matcher = pattern.matcher(type);
        while (matcher.find()) {
            String fullName = matcher.group(0);
            String shortName = matcher.group(2); // 提取类名
            type = type.replace(fullName, shortName);
        }
        return type;
    }
}
